import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    meta: {
      title: '首页'
    },
    component: () => import('../layouts/default.vue'),
    children: [
      {
        path: 'index',
        component: () => import('../views/home/index.vue'),
        meta: {
          title: '首页'
        }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

const indexRoute = '/index'

router.beforeEach((to, from, next) => {
  console.log(to.path)
  if (to.path === '/') {
    next({
      path: '/index'
    })
  } else {
    next()
  }
})

export default router
export { indexRoute }
